package com.example.node.config;

import com.example.node.utils.IPUtils;

import java.io.Serializable;

/*
 * @className: NodeConfig
 * @author: chentao
 * @date: 2025/10/25 下午5:17
 * @Version: 1.0
 * @description:
 */
public class NodeConfig implements Serializable {

    //本节点的名称
    private String serverName = "default";

    //本节点的id
    private Long serverId;

    //本节点的ip
    private String serverIp;

    //本节点的端口
    private Long serverPort;

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    public Long getServerId() {
        return serverId;
    }

    public void setServerId(Long serverId) {
        this.serverId = serverId;
    }

    public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public Long getServerPort() {
        return serverPort;
    }

    public void setServerPort(Long serverPort) {
        this.serverPort = serverPort;
    }

    @Override
    public String toString() {
        return "NodeConfig{" +
                "serverName='" + serverName + '\'' +
                ", serverId=" + serverId +
                ", serverIp='" + serverIp + '\'' +
                ", serverPort=" + serverPort +
                '}';
    }

    public NodeConfig(Long serverPort) {
        this.serverPort = serverPort;
        this.serverIp = IPUtils.getIP();
        this.serverId = IPUtils.combineIpAndPort(this.serverIp , this.serverPort);
    }
}
